package com.hhkj.api.sale.common.component.checker;

import cn.hutool.core.util.ObjectUtil;
import com.hhkj.admin.sale.domain.Sale;
import com.hhkj.admin.sale.service.base.SaleService;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ApiSaleChecker
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/10/25 15:01
 */
@Component
public class ApiSaleChecker {

    @Autowired
    private SaleService saleService;

    /**
     * 校验手机号是否注册
     *
     * @param mobile 手机号
     */
    public void checkerMobileRegister(String mobile) {
        Sale salePo = saleService.getByMobile(mobile);
        if (ObjectUtil.isNotNull(salePo)) {
            throw new GlobalException("该手机号已注册");
        }
    }

    /**
     * 校验手机号是否注册
     *
     * @param mobile 手机号
     */
    public void checkerMobileReset(String mobile) {
        Sale salePo = saleService.getByMobile(mobile);
        if (ObjectUtil.isNull(salePo)) {
            throw new GlobalException("该手机号未注册");
        }
    }

    /**
     * 校验手机号是否注册
     *
     * @param mobile 手机号
     */
    public void checkerMobileUpdate(String mobile) {
        Sale salePo = saleService.getByMobile(mobile);
        if (ObjectUtil.isNull(salePo)) {
            throw new GlobalException("该手机号未注册");
        }
    }
}
